Ext.define('SKJF.view.PEMBELIAN.v_purchasertn_form', {
	extend	: 'Ext.form.Panel',
	
	alias	: 'widget.v_purchasertn_form',
	
	//region:'east',
	//id: 'east-region-container',
	
	title		: 'Create/Update purchasertn',
    bodyPadding	: 5,
    autoScroll	: true,
    
    initComponent: function(){
    	/*
		 * Deklarasi variable setiap field
		 */
		
		
		var APA_IMPORT_store = Ext.create('Ext.data.Store', {
			fields: ['value', 'display'],
			data : [{"value":"1", "display":"YA"},{"value":"0", "display":"TIDAK"}]
		});
		var mstsupp_store = Ext.create('SKJF.store.s_mstsupplier');
		mstsupp_store.load();
		var mstcurrency_store = Ext.create('SKJF.store.s_mstcurrency',{autoLoad:true});
		var terimabarang_store = Ext.create('SKJF.store.s_terimabarang',{autoLoad:true});
		
		var NOMOR_PURCHASE_RETURN_field = Ext.create('Ext.form.field.Text', {
			itemId: 'NOMOR_PURCHASE_RETURN_field',
			name: 'NOMOR_PURCHASE_RETURN', /* column name of table */
			fieldLabel: 'NOMOR_PURCHASE_RETURN',
			allowBlank: false /* jika primary_key */,
			maxLength: 15 /* length of column name */
		});
		var TANGGAL_PURCHASE_RETURN_field = Ext.create('Ext.form.field.Date', {
			name: 'TANGGAL_PURCHASE_RETURN', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_PURCHASE_RETURN'
		});
		var NOMOR_LPB_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'NOMOR_LPB', /* column name of table */
			fieldLabel: 'NOMOR_LPB',
			pageSize: 10,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: terimabarang_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{NOMOR_LPB} - {NAMA_SUPPLIER}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{NOMOR_LPB} - {NAMA_SUPPLIER}',
				'</tpl>'
			),
			valueField: 'NOMOR_LPB',
			displayField: 'NOMOR_LPB'
		});
		var APA_IMPORT_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'APA_IMPORT', /* column name of table */
			fieldLabel: 'APA_IMPORT',
			pageSize: 10,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: APA_IMPORT_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{display}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{display}',
				'</tpl>'
			),
			valueField: 'value',
			displayField: 'display'
		});
		var NAMA_SUPPLIER_field = Ext.create('Ext.form.field.Text', {
			name: 'NAMA_SUPPLIER', /* column name of table */
			fieldLabel: 'NAMA_SUPPLIER',
			readOnly: true
		});
		var ALAMAT_SUPPLIER_field = Ext.create('Ext.form.field.Text', {
			name: 'ALAMAT_SUPPLIER', /* column name of table */
			fieldLabel: 'ALAMAT_SUPPLIER',
			readOnly: true
		});
		var TELPON_SUPPLIER_field = Ext.create('Ext.form.field.Text', {
			name: 'TELPON_SUPPLIER', /* column name of table */
			fieldLabel: 'TELPON_SUPPLIER',
			readOnly: true
		});
		var FAX_SUPPLIER_field = Ext.create('Ext.form.field.Text', {
			name: 'FAX_SUPPLIER', /* column name of table */
			fieldLabel: 'FAX_SUPPLIER',
			readOnly: true
		});
		var KODE_SUPPLIER_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'KODE_SUPPLIER', /* column name of table */
			fieldLabel: 'KODE_SUPPLIER',
			pageSize: 10,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: mstsupp_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{KODE_SUPPLIER} - {NAMA_SUPPLIER}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{KODE_SUPPLIER} - {NAMA_SUPPLIER}',
				'</tpl>'
			),
			valueField: 'KODE_SUPPLIER',
			displayField: 'KODE_SUPPLIER',
			enableKeyEvents: true,
			listeners: {
				select: function(combo, records, e){
					var ns = records[0].data.NAMA_SUPPLIER;
					NAMA_SUPPLIER_field.setValue(ns);
					ALAMAT_SUPPLIER_field.setValue(records[0].data.ALAMAT_1);
					TELPON_SUPPLIER_field.setValue(records[0].data.TELPON);
					FAX_SUPPLIER_field.setValue(records[0].data.FAX);
				}
			}
		});
		var CURRENCY_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'CURRENCY', /* column name of table */
			fieldLabel: 'CURRENCY',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: mstcurrency_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{CURRENCY} - {NEGARA}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{CURRENCY}',
				'</tpl>'
			),
			valueField: 'CURRENCY',
			displayField: 'CURRENCY'
		});
		var KURS_field = Ext.create('Ext.form.field.Number', {
			name: 'KURS', /* column name of table */
			fieldLabel: 'KURS',
			maxLength: 11 /* length of column name */
		});
		var SUB_TOTAL_field = Ext.create('Ext.form.field.Number', {
			name: 'SUB_TOTAL', /* column name of table */
			fieldLabel: 'SUB_TOTAL',
			readOnly: true
		});
		var PPN_field = Ext.create('Ext.form.field.Text', {
			name: 'PPN', /* column name of table */
			fieldLabel: 'PPN',
			value: '10%',
			readOnly: true
		});
		var TOTAL_field = Ext.create('Ext.form.field.Number', {
			name: 'TOTAL', /* column name of table */
			fieldLabel: 'TOTAL',
			readOnly: true
		});
		var MATERAI_field = Ext.create('Ext.form.field.Number', {
			name: 'MATERAI', /* column name of table */
			fieldLabel: 'MATERAI',
			readOnly: true,
		});
		var DIBUAT_OLEH_field = Ext.create('Ext.form.field.Text', {
			name: 'DIBUAT_OLEH', /* column name of table */
			fieldLabel: 'DIBUAT_OLEH',
			value: username,
			readOnly: true
		});
		var JUMLAH_EDIT_field = Ext.create('Ext.form.field.Number', {
			name: 'JUMLAH_EDIT', /* column name of table */
			fieldLabel: 'JUMLAH_EDIT',
			readOnly: true
		});
		var TANGGAL_EDIT_field = Ext.create('Ext.form.field.Date', {
			name: 'TANGGAL_EDIT', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_EDIT',
			value: new Date(),
			readOnly: true
		});
		var INFO_field = Ext.create('Ext.form.field.Text', {
			name: 'INFO', /* column name of table */
			fieldLabel: 'INFO',
			maxLength: 50 /* length of column name */
		});		
        Ext.apply(this, {
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 120,
                msgTarget: 'qtip',
				anchor: '100%'
            },
			defaultType: 'textfield',
            items: [NOMOR_PURCHASE_RETURN_field,TANGGAL_PURCHASE_RETURN_field,NOMOR_LPB_field,APA_IMPORT_field,KODE_SUPPLIER_field,NAMA_SUPPLIER_field,ALAMAT_SUPPLIER_field,TELPON_SUPPLIER_field,FAX_SUPPLIER_field,CURRENCY_field,KURS_field,SUB_TOTAL_field,PPN_field,TOTAL_field,MATERAI_field,DIBUAT_OLEH_field,JUMLAH_EDIT_field,TANGGAL_EDIT_field,INFO_field],
			
	        buttons: [{
                iconCls: 'icon-save',
                itemId: 'save',
                text: 'Save',
                disabled: true,
                action: 'save'
            }, {
                iconCls: 'icon-add',
				itemId: 'create',
                text: 'Create',
                action: 'create'
            }, {
                iconCls: 'icon-reset',
                text: 'Cancel',
                action: 'cancel'
            }]
        });
        
        this.callParent();
    }
});